<?php

include ('../session.php');
include ('../db.php');
include ('../functions.php');
include ('config.php');

if ($action == 'add')
{
  print_r ($_POST);

  $c_name = mysql_clean ($name);
  $c_level = intval ($level);
  $c_raceid = intval ($race);
  $c_classid = intval ($class);

  $query = "select member_id
            from " . DKP_MEMBERS . "
            where member_name = '$c_name'";
  $result = mysql_query ($query);

  $row = mysql_fetch_array ($result);

  if ($row)
  {
  }

  $query = "select idvalue
            from ids
            where idid = " . ID_MEMBER;
  $result = mysql_query ($query);

  $row = mysql_fetch_array ($result);

  $memberid = $row['idvalue'];
  $c_memberid = intval ($memberid);

  $query = "insert into " . DKP_MEMBERS . "
            (member_id, member_name, member_level, race_id, class_id)
            values ($c_memberid, '$c_name', $c_level, $c_raceid, $c_classid)";
  $result = mysql_query ($query);

  $query = "update ids
            set idvalue = " . intval ($memberid + 1) . "
            where idid = " . ID_MEMBER;
  $result = mysql_query ($query);
}
else if ($action == 'update')
{
}
else if ($action == 'remove')
{
}

$output = '';

$output .= "
<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\">
<html>
  <head>
    <title>Panic Points - Add Member</title>
    <link href=\"../general.css\" rel=\"stylesheet\" type=\"text/css\">
  </head>
  <body>";

include ('navigation.php');

$output .= "
    <form name=\"memberform\" id=\"memberform\" action=\"addmember.php\" method=\"POST\">
      <input type=\"hidden\" name=\"action\" id=\"action\" value=\"\">
      <table>
        <tr>
          <td>name</td>
          <td><input type=\"edit\" name=\"name\"></td>
        </tr>
        <tr>
          <td>level</td>
          <td><input type=\"edit\" name=\"level\"></td>
        </tr>
        <tr>
          <td>race</td>
          <td>
            <select name=\"race\">";

$query = "select race_id, race_name
          from " . DKP_RACES . "
          order by race_name asc";
$result = mysql_query ($query);

while ($row = mysql_fetch_array ($result))
{
  $output .= "
              <option value=\"" . $row['race_id'] . "\">" . $row['race_name'] . "</option>";
}

$output .= "
            </select>
          </td>
        </tr>
        <tr>
          <td>class</td>
          <td>
            <select name=\"class\">";

$query = "select class_id, class_name
          from " . DKP_CLASSES . "
          order by class_name asc";
$result = mysql_query ($query);

while ($row = mysql_fetch_array ($result))
{
  $output .= "
              <option value=\"" . $row['class_id'] . "\">" . $row['class_name'] . "</option>";
}

$output .= "
            </select>
          </td>
        </tr>
        <tr>
          <td colspan=\"2\">
            <button onclick=\"document.getElementById ('action').value = 'add'; document.getElementById ('memberform').submit ()\">add</button>&nbsp;
            <button onclick=\"document.getElementById ('action').value = 'update'; document.getElementById ('memberform').submit ()\">update</button>&nbsp;
            <button onclick=\"document.getElementById ('action').value = 'remove'; document.getElementById ('memberform').submit ()\">remove</button>
          </td>
        </tr>
      </table>
    </form>";

$output .= "
  </body>
</html>";

echo $output;
